package fun.parser.postfix;

import fun.parser.lexer.Token;
import fun.parser.lexer.TokenType;

public class PostfixNode {
	private Token token = null;
	private PostfixNodeType type = null;

	public static PostfixNode newOperator(Token token) {
		return new PostfixNode(PostfixNodeType.OPERATOR, token);
	}

	public static PostfixNode newOperand(Token token) {
		return new PostfixNode(PostfixNodeType.OPERAND, token);
	}

	public static PostfixNode newFunction(Token funName) {
		return new FunctionNode(funName);
	}

	public static PostfixNode newFunction(Token funName, PostfixProgram[] args) {
		return new FunctionNode(funName, args);
	}

	// ==========================================================
	protected PostfixNode(PostfixNodeType type, Token tokens) {
		this.type = type;
		this.token = tokens;
	}

	public Token getToken() {
		return this.token;
	}

	public TokenType getTokenType() {
		return this.token.getTokenType();
	}

	// ���ȼ�ֻ��"������"�����壬������ͺ�����ö�û�����ȼ�
	public int getPriority() {
		if (true == this.isOperator())
			return PostfixNodeUtils.getOperatorPriority(this.getTokenType());
		return -1;
	}

	public boolean isOperator() {
		return this.type == PostfixNodeType.OPERATOR;
	}

	public boolean isOperand() {
		return this.type == PostfixNodeType.OPERAND;
	}

	public boolean isFunction() {
		return this.type == PostfixNodeType.FUNCTION;
	}

	public String toString() {
		return token.getImage();
	}
}
